package com.jgx.util;


import java.sql.*;

public class Dbutil509 {

    public static Connection getConnection(){
        //1、加载驱动
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();

        }
        //2、创建连接
        Connection connection = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hoteldb","root","123456");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        System.out.println("创建连接成功");
        return connection;
    }
    //7、关闭资源
    public static void closeAll(ResultSet resultSet, Statement statement, Connection connection) throws SQLException {
        if (resultSet!=null){
            resultSet.close();
        }
        if (resultSet!=null){
            statement.close();
        }
        if (resultSet!=null){
            connection.close();
        }
    }
}
